home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 1750 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.2 KB

  1. Path: news1.h1.usa.pipeline.com!usenet
  2. From: grantp@usa.pipeline.com
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: C++  Vs. C  & Efficiency
  5. Date: 12 Jan 1996 14:16:33 GMT
  6. Organization: Pipeline USA
  7. Message-ID: <4d5qg1$3fa@news1.usa.pipeline.com>
  8. NNTP-Posting-Host: pipe11.h1.usa.pipeline.com
  9. X-PipeUser: grantp
  10. X-PipeHub: usa.pipeline.com
  11. X-PipeGCOS: (Pete)
  12. X-Newsreader: Pipeline USA v3.3.0
  13.  
  14. On Jan 12, 1996 09:34:03 in article <C++  Vs. C  & Efficiency>,
  15. 'edwint@infomatch.com (Edwin Tam)' wrote: 
  16.  
  17.  
  18. >Hello, 
  19. >I have recently become proficient in C++ programming and was wondering
  20. about 
  21. >the advantages of C++ vs C. One thing that has always sorta bugged me
  22. though 
  23. >the question of the extra overhead required by C++ ( compiler wise ). 
  24.  
  25. There's no inherent extra overhead in C++ over C. 
  26.  
  27. >It seems as if every C++ programmer wants to 'object'ize every thing
  28. without 
  29. >considering the overhead incurred by objects. 
  30. If that was the case -- and it's not -- then the 'blame' belongs to the 
  31. programmer, not the language. 
  32.  
  33. >Has anyone got any opinions or idea of the overhead imposed by C++??  
  34.  
  35. As I already said, none. 
  36.  
  37. >A simple ponder : For every object instance, every variable of that class
  38. is  
  39. >duplicated... even if its not required.  
  40. Assuming you're referring to non-static members -- yes.  Just like in C 
  41. and Pascal and.... you name it.  Would you want it any other way? 
  42.  
  43. But here's where the power of C++ comes in:  You can define: 
  44.  
  45. class Base { ... variables that all should have }; 
  46. class fooDerived : public Base { variables needed also by fooDerived }; 
  47. class barDerived : public fooDerived { additional variables needed 
  48.                       by barDerived }; 
  49.  
  50. and select which kind of object to create based on your needs. 
  51. And all this comes at no extra run time cost (over C structures) 
  52. to boot! 
  53.  
  54. The extra "cost" you may be concerned about, has to do with 
  55. virtual functions and virtual derivation.  This cost is not 
  56. real as equivalent C code "costs" just as much -- and 
  57. in some cases more -- than the virtual dispatch mechanism of C++. 
  58.  
  59. On the other side of the coin, C++ has inline, while C doesn't. 
  60. This can make C++ code more efficient. 
  61.  
  62. -- 
  63.  
  64. Pete
  65.